﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FantastPlatform.Framework.IModel;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.Exception;
using FantastPlatform.Framework.Common;
using Newtonsoft.Json;
using FantastPlatform.Framework.Common.Serializable;

namespace FantastPlatform.Framework.Model
{
    public class Post : Item, IPost
    { 
        
        [JsonConverter(typeof(InterfaceConverter<Organization>))]
        public virtual IOrganization Organization { get; set; }
        [JsonConverter(typeof(InterfaceConverter<Position>))]
        public virtual IPosition Position { get; set; }
        
        public override string Name
        {
            get
            {
                Check.Require<ArgumentNullException>(Organization != null, "组织不能为空！");
                Check.Require<ArgumentNullException>(Position != null, "职位不能为空！");
                Check.Require<ArgumentNullException>(PostResponsibility != null, "分管工作不能为空！");
                return Organization.Name + "-" + Position.Name+"("+PostResponsibility.Name+")"; 
            }
        }



        #region IPost 成员

        [JsonConverter(typeof(InterfaceConverter<Post>))]
        public virtual IPost Leader
        {
            get;
            set;
        }
        [JsonConverter(typeof(InterfaceConverter<PostResponsibility>))]
        public virtual IPostResponsibility PostResponsibility
        {
            get;
            set;
        }

        #endregion

        #region IPost 成员
         
        [JsonIgnore]
        public virtual IList<IEmployeePost> EmployeePosts
        {
            get;
            set;
        }

        #endregion
    }
}
